<!DOCTYPE html>
<html>
<body>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script type="module">
import {MockBatteryMonitor} from './resources/mock-battery-monitor.js';

const mock = new MockBatteryMonitor();

promise_test(async _ => {
  mock.setBatteryStatus(false, 10, 20, 0.5);

  let battery = await navigator.getBattery();
  const newLevel = 0.6;
  const levelChange =
      new Promise(resolve => battery.addEventListener('levelchange', resolve));
  battery = null;
  gc();

  mock.setBatteryStatus(false, 10, 20, newLevel);
  await levelChange;
}, 'BatteryManager object is not garbage-collected with listeners attached');
</script>
</body>
</html>
